package com.cold.demo.web.util;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author x c
 * @Email 378661553@qq.com
 * @Date Created in 2020/1/8 12:47
 */
public class RequestUtil {

    public static String getRequestParams(HttpServletRequest request) {
        String servletPath = request.getServletPath();
        Map<String, String[]> parameterMap = request.getParameterMap();
        if (parameterMap == null || parameterMap.size() == 0) {
            return servletPath;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(servletPath);
        if (parameterMap.size() > 0) {
            sb.append("?");
            for (String key : parameterMap.keySet()) {
                String[] values = parameterMap.get(key);
                if (values != null && values.length > 0) {
                    for (String value : values) {
                        sb.append(key).append('=').append(value).append('&');
                    }
                }
            }
        }
        return sb.toString();
    }


}
